home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Digital Signature Forger / Source / Control.c next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  3.2 KB  |  171 lines  |  [TEXT/KAHL]

  1. /*
  2.  *  Forger
  3.  *  An init for forcing AOCE digital signitures to always succeed or fail.
  4.  *
  5.  *  Copyright © 1993 by David Shayer.  All rights reserved.
  6.  *
  7.  *  File: Control.c
  8.  */
  9.  
  10.  
  11. /***************************** Includes *******************************/
  12.  
  13. #include <Traps.h>
  14.  
  15. #include "Control.h"
  16.  
  17.  
  18. /***************************** Globals *******************************/
  19.  
  20. DataRecPtr    gDataPtr;
  21.  
  22. /***************************** Routines *******************************/
  23.  
  24. void main (void)
  25. {
  26.     Init();
  27.     CheckOCE();
  28.     gDataPtr=GetDataAddr ();
  29.     HandleDialog();
  30. }
  31.  
  32.  
  33. void Init (void)
  34. {
  35.     MaxApplZone();
  36.     InitGraf(&thePort);
  37.     InitFonts();
  38.     InitWindows();
  39.     InitMenus();
  40.     TEInit();
  41.     InitDialogs(NULL);
  42.     FlushEvents(everyEvent,0);
  43. }
  44.  
  45.  
  46. // check for digital sigs, the quick and dirty way
  47. void CheckOCE (void)
  48. {
  49.     long    UnimpAddr, DigSigAddr;
  50.     
  51.     DigSigAddr = NGetTrapAddress (_DigitalSignature, ToolTrap);
  52.     UnimpAddr = GetTrapAddress (_Unimplemented);
  53.     if (UnimpAddr==DigSigAddr)
  54.     {
  55.         Alert (128, NULL);
  56.         ExitToShell ();
  57.     }
  58. }
  59.  
  60. void HandleDialog (void)
  61. {    
  62.     DialogPtr    DPtr;
  63.     short        item;
  64.     Rect        rect;
  65.     Handle        hdl;    
  66.     GDHandle    gdh;
  67.     
  68.     gdh = GetMainDevice();
  69.     if ((**((**gdh).gdPMap)).pixelSize>=4)
  70.         DPtr=GetNewDialog (rMainDlog, NULL, (WindowPtr)-1);
  71.     else
  72.         DPtr=GetNewDialog (rBWMainDlog, NULL, (WindowPtr)-1);
  73.  
  74.     GetDItem (DPtr, rRect1, &item, &hdl, &rect);
  75.     SetDItem (DPtr, rRect1, item, DrawRect, &rect);
  76.     GetDItem (DPtr, rRect2, &item, &hdl, &rect);
  77.     SetDItem (DPtr, rRect2, item, DrawRect, &rect);
  78.     if (gDataPtr->On)
  79.         GetDItem (DPtr, rOn, &item, &hdl, &rect);
  80.     else
  81.         GetDItem (DPtr, rOff, &item, &hdl, &rect);
  82.     SetCtlValue (hdl,1);
  83.     if (gDataPtr->Succeed)
  84.         GetDItem (DPtr, rAlways, &item, &hdl, &rect);
  85.     else
  86.         GetDItem (DPtr, rNever, &item, &hdl, &rect);
  87.     SetCtlValue (hdl,1);
  88.     
  89.     do
  90.     {
  91.         ModalDialog (NULL, &item);
  92.         switch (item)
  93.         {
  94.             case rAbout:
  95.                 AboutBox ();
  96.                 break;
  97.             case rOn:
  98.                 GetDItem (DPtr, rOn, &item, &hdl, &rect);
  99.                 SetCtlValue (hdl,1);
  100.                 GetDItem (DPtr, rOff, &item, &hdl, &rect);
  101.                 SetCtlValue (hdl,0);
  102.                 gDataPtr->On=1;
  103.                 break;
  104.             case rOff:
  105.                 GetDItem (DPtr, rOn, &item, &hdl, &rect);
  106.                 SetCtlValue (hdl,0);
  107.                 GetDItem (DPtr, rOff, &item, &hdl, &rect);
  108.                 SetCtlValue (hdl,1);
  109.                 gDataPtr->On=0;
  110.                 break;
  111.             case rAlways:
  112.                 GetDItem (DPtr, rAlways, &item, &hdl, &rect);
  113.                 SetCtlValue (hdl,1);
  114.                 GetDItem (DPtr, rNever, &item, &hdl, &rect);
  115.                 SetCtlValue (hdl,0);
  116.                 gDataPtr->Succeed=1;
  117.                 break;
  118.             case rNever:
  119.                 GetDItem (DPtr, rAlways, &item, &hdl, &rect);
  120.                 SetCtlValue (hdl,0);
  121.                 GetDItem (DPtr, rNever, &item, &hdl, &rect);
  122.                 SetCtlValue (hdl,1);
  123.                 gDataPtr->Succeed=0;
  124.                 break;
  125.             default:
  126.                 break;
  127.         }
  128.     }
  129.     while (item!=rQuit);
  130.     DisposDialog (DPtr);
  131. }
  132.  
  133.  
  134. void AboutBox (void)
  135. {
  136.     GDHandle    gdh;
  137.     
  138.     gdh = GetMainDevice();
  139.     if ((**((**gdh).gdPMap)).pixelSize>=4)
  140.         Alert (rColorAbout, NULL);
  141.     else
  142.         Alert (rBWAbout, NULL);
  143. }
  144.  
  145.  
  146. DataRecPtr GetDataAddr (void)
  147. {
  148.     DataRecPtr        DataPtr;
  149.  
  150.     asm
  151.     {
  152.         MOVE.L    #kControlAddr, D0
  153.         DC.W    _DigitalSignature
  154.         MOVE.L    D0, DataPtr
  155.     }
  156.     return DataPtr;
  157. }
  158.  
  159.  
  160. pascal void DrawRect (WindowPtr WindPtr, short ItemNo)
  161. {
  162.     short        Item;
  163.     Handle        ItemHdl;
  164.     Rect        ItemRect;
  165.     
  166.     GetDItem (WindPtr, ItemNo, &Item, &ItemHdl, &ItemRect);
  167.     FrameRect (&ItemRect);
  168. }
  169.  
  170.  
  171.